//
//  DLPasswordLoginView.m
//  delongzhitou
//
//  Created by Mr.Wang on 2018/11/23.
//  Copyright © 2018 delongzhitou. All rights reserved.
//

#import "DLPasswordLoginView.h"

@implementation DLPasswordLoginView


- (instancetype) initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self layoutSubControls];
    }
    return self;
}

- (void) layoutSubControls {
    
    //手机号输入框
    CGFloat phoneTFW = self.width - 80;
    CGFloat phoneTFH = 50;
    
    
    UILabel *phoneTFLeftLable = [UILabel new];
    phoneTFLeftLable.frame = CGRectMake(0, 0, 80, phoneTFH);
    phoneTFLeftLable.text = @"账    号：";
    phoneTFLeftLable.textAlignment = NSTextAlignmentLeft;
    phoneTFLeftLable.font = kSystemFont(18);
    phoneTFLeftLable.textColor = kDLNormalBlackColor;
    [self addSubview:phoneTFLeftLable];
    
    UITextField *phoneTF = [UITextField new];
    phoneTF.frame = CGRectMake(phoneTFLeftLable.right, phoneTFLeftLable.top, phoneTFW, phoneTFH);
    phoneTF.borderStyle = UITextBorderStyleNone;
    phoneTF.keyboardType = UIKeyboardTypeNumberPad;
    phoneTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    phoneTF.font = kSystemFont(18);
    phoneTF.placeholder = @"请输入账号";
    [phoneTF addTarget:self action:@selector(phoneTFTextChange:) forControlEvents:UIControlEventEditingChanged];
    [self addSubview:phoneTF];
    self.phoneTF = phoneTF;
    
    UIView *lineView = [UIView new];
    lineView.frame = CGRectMake(phoneTF.left, phoneTF.bottom, phoneTF.width, 1);
    lineView.backgroundColor = kDLNormalBlackColor;
    [self addSubview:lineView];
    
    
    UILabel *passwordTFLeftLable = [UILabel new];
    passwordTFLeftLable.frame = CGRectMake(phoneTFLeftLable.left, lineView.bottom, phoneTFLeftLable.width, phoneTFH);
    passwordTFLeftLable.text = @"密    码：";
    passwordTFLeftLable.textAlignment = NSTextAlignmentLeft;
    passwordTFLeftLable.font = kSystemFont(18);
    passwordTFLeftLable.textColor = kDLNormalBlackColor;
    [self addSubview:passwordTFLeftLable];
    
    
    UITextField *passwordTF = [UITextField new];
    passwordTF.frame = CGRectMake(passwordTFLeftLable.right, passwordTFLeftLable.top, phoneTF.width, phoneTFH);
    passwordTF.borderStyle = UITextBorderStyleNone;
    passwordTF.secureTextEntry = YES;
    passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    passwordTF.font = kSystemFont(18);
    passwordTF.placeholder = @"请输入密码";
    [passwordTF addTarget:self action:@selector(passwordTFTextChange:) forControlEvents:UIControlEventEditingChanged];
    [self addSubview:passwordTF];
    self.passwordTF = passwordTF;
    
}

- (void)phoneTFTextChange:(UITextField *)textField {
    
    if (textField.text.length >11) {
        NSString *str = textField.text;
        textField.text = [str substringToIndex:11];
    }
}

- (void)passwordTFTextChange:(UITextField *)textField {
    
    if (textField.text.length >16) {
        NSString *str = textField.text;
        textField.text = [str substringToIndex:16];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
